/**
 * 
 */
package cx3k.GUI;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.border.*;
import javax.swing.*;

/**
 * @author Chris
 *
 */
public class ClassDisplay extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JLabel jlClass;
	JComboBox jcbClasses;
	JButton jbOptions;
	JComponent jcPlaceholder;
	ClassMouseListener CML;

	
	public ClassDisplay(Course course) {
		this.setPreferredSize(new Dimension(200, 50));
		this.setBackground(MainWindow.MAINCOLOR);
		this.setBorder(new LineBorder(Color.black));
		
		this.CML = new ClassMouseListener();
		
		this.jbOptions = new JButton(">");
		this.jbOptions.setBackground(MainWindow.MAINCOLOR);
		this.jbOptions.setBorder(null);
		this.jbOptions.setCursor(new Cursor(Cursor.HAND_CURSOR));
		
		//if (course group is 1) {
			jcPlaceholder = new JLabel(course.getDegreeProgram() + " " + course.getCourseNum());
			this.jcPlaceholder.addMouseListener(CML);
		/*}
		else { // group has more than one course
			Course[] courses = (Course[]) group.getCourses().toArray();
			this.jcPlaceholder = new JComboBox();
			this.jcPlaceholder.addItem("Choose One");
			for (int i = 0; i<group.length; i++) {
				this.jcPlaceholder.addItem(courses[i]);
			}
		}
		*/
		this.jcPlaceholder.setCursor(new Cursor(Cursor.HAND_CURSOR));
		this.add(jcPlaceholder);
		this.add(jbOptions);
	}
	
	private class ClassMouseListener implements MouseListener {

		@Override
		public void mouseClicked(MouseEvent me) {
			// TODO Auto-generated method stub
			if (me.getButton() == MouseEvent.BUTTON3) {
				JPopupMenu jpm = new JPopupMenu();
				JMenu moveMenu, yearMenu0, yearMenu1;
				moveMenu = new JMenu("Move Class");
				yearMenu0 = new JMenu("Year 1");
				yearMenu1 = new JMenu("Year 2");
				
				yearMenu0.add(new JMenuItem("Fall"));
				yearMenu0.add(new JMenuItem("Winter"));
				yearMenu0.add(new JMenuItem("Spring"));
				yearMenu0.add(new JMenuItem("Summer"));
				yearMenu1.add(new JMenuItem("Fall"));
				yearMenu1.add(new JMenuItem("Winter"));
				yearMenu1.add(new JMenuItem("Spring"));
				yearMenu1.add(new JMenuItem("Summer"));
				
				moveMenu.add(yearMenu0);
				moveMenu.add(yearMenu1);
				jpm.add(moveMenu);
				jpm.add(new JMenuItem("Delete"));
				jpm.show(jbOptions, 0, 0);
			}
		}

		@Override
		public void mouseEntered(MouseEvent arg0) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mouseExited(MouseEvent arg0) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mousePressed(MouseEvent arg0) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mouseReleased(MouseEvent arg0) {
			// TODO Auto-generated method stub
			
		}
		
	}
	
	private class OptionListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent arg0) {
			// TODO Auto-generated method stub
			JPopupMenu jpm = new JPopupMenu();
			JMenu moveMenu, yearMenu0, yearMenu1;
			moveMenu = new JMenu("Move Class");
			yearMenu0 = new JMenu("Year 1");
			yearMenu1 = new JMenu("Year 2");
			
			yearMenu0.add(new JMenuItem("Fall"));
			yearMenu0.add(new JMenuItem("Winter"));
			yearMenu0.add(new JMenuItem("Spring"));
			yearMenu0.add(new JMenuItem("Summer"));
			yearMenu1.add(new JMenuItem("Fall"));
			yearMenu1.add(new JMenuItem("Winter"));
			yearMenu1.add(new JMenuItem("Spring"));
			yearMenu1.add(new JMenuItem("Summer"));
			
			moveMenu.add(yearMenu0);
			moveMenu.add(yearMenu1);
			jpm.add(moveMenu);
			jpm.add(new JMenuItem("Delete"));
			jpm.show(jbOptions, 0, 0);
		}
		
	}


	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
	}


	public void addClass(String string) {
		// TODO Auto-generated method stub
		
	}

}
